package net.aiion.weave.spi.xml;

import java.util.ServiceLoader;

import net.aiion.weave.spi.resources.Resource;

public abstract class XmlSourceFactory
{
    private static XmlSourceFactory instance;

    public XmlSourceFactory() {
    }

    public abstract XmlSource createReader(Resource aResource);

    public abstract XmlGenerator createGenerator();

    public static XmlSourceFactory getInstance() {
        if (instance == null) {
            for (XmlSourceFactory xmlSourceFactory : XmlSourceFactoryServiceLoader.SERVICE_LOADER) {
                instance = xmlSourceFactory;
                break;
            }
        }

        return instance;
    }

    private static final class XmlSourceFactoryServiceLoader
    {
        private static final ServiceLoader<XmlSourceFactory> SERVICE_LOADER = ServiceLoader
            .load(XmlSourceFactory.class);

        private XmlSourceFactoryServiceLoader() {
        }
    }
}
